package com.tc168.cp306.b06.iview;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.tc168.cp306.b06.R;


//


public class LoginPop extends Dialog {


    public LoginPop(Context context) {
        super(context);
    }

    public LoginPop(Context context, int theme) {
        super(context, theme);
    }

    public static class Builder {
        private Context context;

        private View contentView;

        private OnClickListener loginbuttonClickLister;


        public Builder(Context context) {
            this.context = context;
        }

//
//        public Builder setcouent(String couent) {
//            this.couent = couent;
//            return this;
//        }

        public Builder setLoginButton(OnClickListener listener) {
            this.loginbuttonClickLister = listener;
            return this;
        }


        public Builder setContentView(View v) {
            this.contentView = v;
            return this;
        }


        public LoginPop create() {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            // instantiate the dialog with the custom Theme
            final LoginPop dialog = new LoginPop(context, R.style.Dialog);
            View layout = inflater.inflate(R.layout.dialog_login, null);

            //找控件
            LinearLayout recycle = (LinearLayout) layout.findViewById(R.id.recycle);
            Button loginbt = (Button) layout.findViewById(R.id.login_bt);
            final EditText passwordet = (EditText) layout.findViewById(R.id.passwordet);
            final EditText nameet = (EditText) layout.findViewById(R.id.name_et);


            dialog.addContentView(layout, new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));


            loginbt.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    String name = nameet.getText().toString().trim();
                    String password = passwordet.getText().toString().trim();

                    loginbuttonClickLister.onClick(dialog,
                            DialogInterface.BUTTON_NEGATIVE, name, password);
                }
            });
            recycle.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dialog.dismiss();
                }
            });

            
            dialog.setContentView(layout);
            return dialog;
        }

    }


    public interface OnClickListener {
        void onClick(DialogInterface var1, int var2, String name, String password);
    }
}
